<?php 
/**
 * ELind Openapi SDK For PHP, Version:1.0
 * Api WebSite :http://open.10ss.net/
 * Api Doc :http://doc.10ss.net/
 * @filename : print.class.php
 * @author   : heqian@yilianyun.net
 * @date     : 2016-07-11
 */
class Message
{
    private $app_id = "75a2fa06-2c9a-40fb-89bb-2cdf4806806c";

    public function sendMessage($palyers=array(),$content=null){
        $content = array(
            "en" => $content
        );

        $fields = array(
            'app_id' => $this->app_id,
            'include_player_ids' => $palyers,//array('6b945372-433d-4cb5-a415-f863b8ff1804'),
            'data' => array("foo" => "bar"),
            'contents' => $content,
	    'android_sound' => 'explode_sound'
        );

        $fields = json_encode($fields);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
            'Authorization: Basic MGVlYTFlNWQtYWFhNS00ZDgwLThmMDQtMjM0YjE5YzAzZjdh'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
    public function addpalyer(){
        $fields = array(
            'app_id' => $this->app_id,
            'identifier' => "ce777617da7f548fe7a9ab6febb56cf39fba6d382000c0395666288d961ee566",
            'language' => "zh-Hans",
            'timezone' => "-28800",
            'game_version' => "1.0",
            'device_type' => "1",
        );

        $fields = json_encode($fields);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/players");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
}
 ?>